<template>
<!--20210607  zaq  快速添加-->
  <div>
    <el-button @click="quickAddVisible=true">快速添加</el-button>
    <el-dialog
        title="快速添加"
        v-model="quickAddVisible"
        width="30%"
        :close-on-click-modal="false"
    >
      <el-select v-model="myChoose" placeholder="请选择">
        <el-option
            v-for="item in Lists"
            :key="{kMId:item.kMId,mText:item.mText}"
            :label="item.mName"
            :value="{kMId:item.kMId,mText:item.mText}">
        </el-option>
      </el-select><br>
      <span style="color: #72767b">
            {{myChoose.mText}}
          </span>
      <template #footer>
    <span class="dialog-footer">
      <el-button type="primary" @click="submit(myChoose)">确 定</el-button>
    </span>
      </template>
    </el-dialog>

    <!--    成功信息对话框-->
    <el-dialog
        title="提示"
        v-model="successDialog.visible"
        width="30%"
        :before-close="handleClose">

      <el-result icon="success" title="快速添加成功" :subTitle="successDialog.message"/>

      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="successDialog.visible = false">确 定</el-button>
        </span>
      </template>
    </el-dialog>

    <!--    失败信息对话框-->
    <el-dialog
        title="提示"
        v-model="failDialog.visible"
        width="30%"
        :before-close="handleClose">

      <el-result icon="error" title="快速添加失败" :subTitle="failDialog.message"/>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="failDialog.visible = false">取 消</el-button>
          <el-button type="primary" @click="failDialog.visible = false">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import moment from "moment";
import {getQuickAdd_0000,insert_17001} from "../api";

export default {
  name: "QuickAdd",
  data(){
    return{
      // 成功信息
      successDialog:{
        visible:false,
        message:'',
      },
      // 失败信息
      failDialog:{
        visible:false,
        message:'',
      },
      quickAddVisible:true,
      Lists:null,
      myChoose:{kMId:null,mText:null},
    }
  },
  mounted() {
    this.setLists()
  },
  methods:{
    submit(myChoose){
      const _this=this
      var body={
        kMId:myChoose.kMId,
        uId:sessionStorage.getItem("uId"),
        mDate:parseInt(moment(new Date()).format("yyyyMMDD"))
      }
      insert_17001(body).then(resp=>{
        if(resp.code>0){
          //弹出成功提示
          _this.successDialog.message=resp.note;
          _this.successDialog.visible=true;



        }else{
          //弹出失败信息
          _this.failDialog.message=resp.note;
          _this.failDialog.visible=true;
        }
      }).catch(err=>{
        //弹出失败信息
        _this.failDialog.message='调用接口失败：'+err;
        _this.failDialog.visible=true;
      })
    },
    setLists(){
      const _this=this
      var body={
        uId:sessionStorage.getItem("uId")
      }
      getQuickAdd_0000(body).then(resp=>{
        _this.Lists=resp
      })
    }
  }
}
</script>

<style scoped>

</style>